# 队列？？
from heapq import heappushpop, heappush
from typing import List

class Solution:
    def scheduleCourse(self, courses: List[List[int]]) -> int:
        t, pq = 0, []
        # 二位数据排序i,j; sorted(courses,key=lambda it:it[1]) !!!
        for i, j in sorted(courses, key=lambda it:it[1]):
            t += i
            if t > j:
                # heappushpop什么意思？加pq，出i??
                t += heappushpop(pq, -i)
            else:
                # heappush什么意思？
                heappush(pq, -i)
        return len(pq)